﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;
using System.IO;
using System.Text;

namespace Taxes.KML
{
    public partial class UnitAreaRecent : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var bll = new BLL.region_info();
            var modelList =  bll.GetModelList("");
            store.DataSource = modelList;
            store.DataBind();
        }

        protected void btnExport_Click(object sender, DirectEventArgs e)
        {
            var fileName= Server.MapPath("/我的位置.kml");
            var export = new KML.KMLExport(fileName);
            export.Export();
            FileInfo fi = new FileInfo(fileName);//文件在服务器上的地址
            HttpResponse contextResponse = HttpContext.Current.Response;
            contextResponse.Clear();
            contextResponse.Buffer = true;
            contextResponse.Charset = "GB2312"; //设置了类型为中文防止乱码的出现 
            contextResponse.AppendHeader("Content-Disposition", String.Format("attachment;filename={0}", fileName)); //定义输出文件和文件名 
            contextResponse.AppendHeader("Content-Length", fi.Length.ToString());
            contextResponse.ContentEncoding = Encoding.Default;
            contextResponse.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。 

            contextResponse.WriteFile(fi.FullName);
            contextResponse.Flush();
            contextResponse.End();
        }

        protected void btnSave_Click(object sender, DirectEventArgs e)
        {
            decimal recent;
            if (!decimal.TryParse(tfPrice.Text.Trim(), out recent))
            {
                X.MessageBox.Configure(new MessageBoxConfig() 
                {
                    Title="提示",
                    Message="请输入有效数字",
                    Icon= MessageBox.Icon.INFO
                }).Show();
                return;
            }

            var model = new Model.region_info();
            model.ID =　Convert.ToInt32( tfHiddenID.Text);
            model.region_unit_price = recent;
            var bll = new BLL.region_info();

            if (bll.Update(model))
            {
                window1.Hidden = true;
                X.MessageBox.Configure(new MessageBoxConfig()
                {
                    Title = "提示",
                    Message = "修改成功",
                    Icon = MessageBox.Icon.INFO,
                    Buttons=MessageBox.Button.OK
                }).Show();
                grid.Reload();
            }
            else
            {
                 X.MessageBox.Configure(new MessageBoxConfig()
                {
                    Title = "提示",
                    Message = "修改失败",
                    Icon = MessageBox.Icon.INFO,
                    Buttons=MessageBox.Button.OK
                }).Show();
            }
        }
    }
}